﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Commonality.ValidateModel
{
    public static class CustomValidata 
    {
        /// <summary>
        /// 自定义验证实体类
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        public static ValiResult Validata<T>(T t) where T : class
        {
            Type vType = typeof(T);
            foreach (var propItem in vType.GetProperties())
            {
                if (propItem.IsDefined(typeof(BaseValidateAttribute), true))
                {
                    foreach (var valItem in propItem.GetCustomAttributes<BaseValidateAttribute>())
                    {
                      var valResult=  valItem.ValiResult(propItem.GetValue(t));
                        if (valResult.IsSuccess != true)
                     
                            return valResult;
                        
                    }
                    
                }
            }
            return new ValiResult() { IsSuccess = true };
        }
    
    }
}
